from django.shortcuts import render,reverse
from django.http import HttpResponse,JsonResponse,Http404,HttpResponseRedirect
from myadmin import models
from django.contrib.auth.hashers import make_password,check_password
from .IndexViews import gettypes
from django.views.decorators.csrf import csrf_exempt

import random,requests
# Create your views here.

# 个人中心，我的订单
def mylist(request):
    # 检测是否登录
    VipUser = request.session.get('VipUser')
    if not VipUser['id']:
        return HttpResponse('<script>alert("请先登录");location.href="/login?nextpath=/order/mylist";</script>')

    # 根据用户id获取当前用户的所有订单
    user = models.Users.objects.get(id=VipUser['id'])

    #分配数据
    context={'user':user,'booktypes':gettypes()}

    # 加载模板
    return render(request,'myhome/order/myorderlist.html',context)